#!/bin/sh
#
# Author ： hbaolong@vip.qq.com
#
# Function : 格式化正对特定书的dict文件
#
#
#

if [ $# -ne 1 ]; then
	echo "Usage: $0 dictfile."
	exit
fi

endictdir="/Users/hbaolong/workshop/gitee/3place/ENMYDICT"

exceptdict="/Users/hbaolong/workshop/gitee/3place/ENMYDICT/exceptwords.md"

except_candidate_dict="/Users/hbaolong/workshop/gitee/3place/ENMYDICT/exceptwords_candidate.md"

words_before=`countline $1`
printf "updating "$1" From "$words_before" To "

if [ $1 -nt $except_candidate_dict ];then
	dictfile=$exceptdict

	sed -e "/\[/d" $1 |sed -e "/[-\/–·©〔']/d" >/tmp/tmp.md

	mv /tmp/tmp.md $1

	#line=`cat $endictdir/exceptwords.md`

	for files in `cat $1`
	do
		if ! grep -q -i -w $files $dictfile; then
			echo $files >>/tmp/tmp.md
		fi
	done
	mv /tmp/tmp.md $1

else
	dictfile=$except_candidate_dict

#	mv /tmp/tmp.md $1

	for word in `cat $dictfile`
	do
#		echo $word
		sed -e "/^$word$/d" $1 >/tmp/tmp.md
		mv /tmp/tmp.md $1
	done

fi

words_after=`countline $1`
if [ $words_before -eq $words_after ];then
	printf $words_after
else
	printf "\033[31m"$words_after"\033[0m"
fi


echo ""
